package com.chunxiadong.service.impl;

import com.chunxiadong.entity.FriendLink;
import com.chunxiadong.mapper.FriendLinkMapper;
import com.chunxiadong.service.FriendLinkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @auther QiuShangcheng
 * @create 2021/6/8
 */
@Service
public class FriendLinkServiceImpl implements FriendLinkService {
    @Autowired
    FriendLinkMapper friendLinkMapper;

    @Transactional
    @Override
    public FriendLink queryFriendLinkByBlogAddr(String blogAddr) {
        return friendLinkMapper.queryFriendLinkByBlogAddr(blogAddr);
    }

    @Transactional
    @Override
    public int addFriendLink(FriendLink friendLink) {
        friendLink.setCreateTime(new Date());
        return friendLinkMapper.addFriendLink(friendLink);
    }

    @Transactional
    @Override
    public FriendLink queryFriendLinkById(Integer id) {
        return friendLinkMapper.queryFriendLinkById(id);
    }

    @Transactional
    @Override
    public int updateFriendLink(FriendLink friendLink) {
        return friendLinkMapper.updateFriendLink(friendLink);
    }

    @Transactional
    @Override
    public List<FriendLink> getAllFriendLink() {
        return friendLinkMapper.getAllFriendLink();
    }

    @Transactional
    @Override
    public PageInfo<FriendLink> getAllFriendLinkPageInfo(Integer pageNum, Integer rows) {
        PageHelper.startPage(pageNum,rows);
        List<FriendLink> allFriendLink = friendLinkMapper.getAllFriendLink();
        PageInfo<FriendLink> pageInfo = new PageInfo<>(allFriendLink);
        return pageInfo;
    }

    @Transactional
    @Override
    public int deleteFriendLinkById(Integer id) {
        return friendLinkMapper.deleteFriendLinkById(id);
    }
}
